<?php
	function oh_is_valid_function($s) {
		if (preg_match("/^[a-z_][a-z0-9_]*$/i",$s)) {
			if (function_exists($s)) {
				return true;
			}
		} else {
			return false;
		}
		return false;
	}
	
	function oh_methods($module = "") {
		if ($module == "") {
			$f = get_defined_functions();
			$f = $f["user"];
			$o = array();
			foreach($f as $i) {
				if (substr($i,0,3) == "oh_") {
					$o[] = $i;
				}
			}
			asort($o);
			return $o;
		} else {
			oh($module);
			$f = get_class_methods("oh_class_".$module);
			asort($f);
			return $f;
		}
	}	
	
	function oh_string_to_array($s) {
		$s = explode("," , $s);
		$o = array();
		foreach($s as $i) {
			$i = explode("=>",$i);
			$o[trim($i[0])] = trim($i[1]);
		}
		return $o;
	}
	
	function oh_module_header($config="") {
		
	}

	function oh_get_file_permission($file) {
		return substr(sprintf('%o', fileperms($file)), -4);				
	}		
	
	function oh_wellcome() {
		return '
			<style type="text/css">
				body {margin:0;padding:0;}
				h1	 {padding:10px;background:#507AAA;color:#fff;font-family:Arial,Helvetica,sans-serif;}
			</style>
			<h1><small>Wellcome to </small>oh.framework</h1>
		';
	}
	
	function oh_find_data_source($modules) {
		foreach($modules as $module) {
			if (oh("debug.modules.model"))
				oh_message("Test module '{$module}' to find 'model datasource'");
			
			if (oh_module_exists($module)) {
				if (oh($module)->is_ready()) {
					return $module;
				}
			}
		}
		return null;
	}
	
	
	function oh_implode_key($s,$array,$key) {
		$o = array();		
		foreach($array as $item) {
			if (isset($item->$key)) {
				$o[] = $item->$key;
			} else if (isset($item[$key])) {
				$o[] = $item[$key];
			}
		}
		return implode($s,$o);
	}	
?>
